load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("//test:regression.bzl", "regression_test")

package(features = ["layering_check"])

exports_files(
    ["hi_fanout.tcl"],
    visibility = ["//visibility:public"],
)

TESTS = [
    "buffer_ports1",
    "buffer_ports10",
    "buffer_ports11",
    "buffer_ports11_hier",
    "buffer_ports12",
    "buffer_ports12_hier",
    "buffer_ports3",
    "buffer_ports4",
    "buffer_ports5",
    "buffer_ports6",
    "buffer_ports7",
    "buffer_ports8",
    "buffer_ports9",
    "buffer_varying_lengths",
    "clone_flat",
    "clone_hier",
    "eliminate_dead_logic1",
    "eliminate_dead_logic2",
    "eqy_repair_setup2",
    "eqy_repair_setup5",
    "fanin_fanout1",
    "gain_buffering1",
    "gain_buffering1_hier",
    "gcd_resize",
    "liberty_dont_use",
    "pinswap_flat",
    "pinswap_hier",
    "rebuffer1",
    "rebuffer1_hier",
    "recover_power_verbose",
    "remove_buffers_hier1",
    "remove_buffers1",
    "remove_buffers2",
    "remove_buffers4",
    "remove_buffers4_hier",
    "remove_buffers5",
    "remove_buffers5_hier",
    "remove_buffers6",
    "repair_cap1",
    "repair_cap2",
    "repair_cap3",
    "repair_clk_inverters1",
    "repair_clk_nets1",
    "repair_design1",
    "repair_design2",
    "repair_design3",
    "repair_design3_verbose",
    "repair_design4",
    "repair_design5",
    "repair_fanout1",
    "repair_fanout1_hier",
    "repair_fanout2",
    "repair_fanout2_hier",
    "repair_fanout3",
    "repair_fanout3_hier",
    "repair_fanout4",
    "repair_fanout5",
    "repair_fanout6",
    "repair_fanout6_multi",
    "repair_fanout7",
    "repair_fanout7_multi",
    "repair_fanout7_skip_pin_swap",
    "repair_fanout8",
    "repair_fanout8_multi",
    "repair_hold1",
    "repair_hold10",
    "repair_hold11",
    "repair_hold12",
    "repair_hold13",
    "repair_hold14",
    "repair_hold15",
    "repair_hold1_hier",
    "repair_hold2",
    "repair_hold3",
    "repair_hold4",
    "repair_hold5",
    "repair_hold6",
    "repair_hold7",
    "repair_hold8",
    "repair_hold9",
    "repair_hold9_verbose",
    "repair_setup1",
    "repair_setup1_multi",
    "repair_setup2",
    "repair_setup2_multi",
    "repair_setup3",
    "repair_setup3_multi",
    "repair_setup4",
    "repair_setup4_flat",
    "repair_setup4_hier",
    "repair_setup4_multi",
    "repair_setup4_sequence",
    "repair_setup4_verbose",
    "repair_setup5",
    "repair_setup6",
    "repair_setup6_multi",
    "repair_setup7",
    "repair_setup7_limit",
    "repair_setup7_multi",
    "repair_setup8",
    "repair_setup9",
    "repair_setup9_hier",
    "repair_setup_sizedown",
    "repair_setup_sizeup_match",
    "repair_setup_undo1",
    "repair_setup_undo2",
    "repair_slew1",
    "repair_slew10",
    "repair_slew11",
    "repair_slew12",
    "repair_slew13",
    "repair_slew14",
    "repair_slew15",
    "repair_slew16",
    "repair_slew17",
    "repair_slew2",
    "repair_slew3",
    "repair_slew4",
    "repair_slew5",
    "repair_slew6",
    "repair_slew7",
    "repair_slew8",
    "repair_slew9",
    "repair_tie1",
    "repair_tie2",
    "repair_tie3",
    "repair_tie4",
    "repair_tie5",
    "repair_tie6",
    "repair_tie7",
    "repair_tie8",
    "repair_tie9",
    "repair_tie10_hier",
    "repair_wire1",
    "repair_wire10",
    "repair_wire11",
    "repair_wire2",
    "repair_wire3",
    "repair_wire4",
    "repair_wire5",
    "repair_wire6",
    "repair_wire7",
    "repair_wire8",
    "repair_wire9",
    "replace_arith_modules1",
    "replace_arith_modules2",
    "report_buffers_asap7",
    "report_buffers_gf180",
    "report_buffers_ihp",
    "report_buffers_nangate45",
    "report_buffers_sky130hd",
    "report_buffers_sky130hs",
    "report_design_area",
    "report_dont_touch",
    "report_dont_use",
    "report_dont_use_corners",
    "report_equiv_cells",
    "report_floating_nets1",
    "report_floating_nets2",
    "report_floating_nets3",
    "report_overdriven_nets1",
    "report_overdriven_nets2",
    "report_overdriven_nets3",
    "report_overdriven_nets4",
    "report_overdriven_nets5",
    "report_overdriven_nets6",
    "resize1",
    "resize1_hier",
    "resize4",
    "resize5",
    "resize6",
    "resize_slack1",
    "resize_slack3",
    "set_dont_touch1",
    "set_dont_use1",
    "split_load_hier",
    "repair_setup_vt_swap",
    "repair_setup_vt_swap2",
]

filegroup(
    name = "test_resources",
    # overly broad glob, could be refined later, but
    # symlinks are cheap and OpenROAD binary changes, the common
    # use case is that all tests have to be re-run.
    srcs = glob(
        ["**/*"],
        exclude = [
            test + "." + ext
            for test in TESTS
            for ext in [
                "tcl",
                "py",
            ]
        ],
    ),
)

# Tests that reference other tests
extra_deps = {
    "repair_fanout6_multi": ["repair_fanout6.tcl"],
    "repair_fanout7_multi": ["repair_fanout7.tcl"],
    "repair_fanout7_skip_pin_swap": ["repair_fanout7.tcl"],
    "repair_fanout8_multi": ["repair_fanout8.tcl"],
    "repair_setup1_multi": ["repair_setup1.tcl"],
    "repair_setup2_multi": ["repair_setup2.tcl"],
    "repair_setup3_multi": ["repair_setup3.tcl"],
    "repair_setup4_multi": ["repair_setup4.tcl"],
    "repair_setup4_sequence": ["repair_setup4.tcl"],
    "repair_setup6_multi": ["repair_setup6.tcl"],
    "repair_setup7_multi": ["repair_setup7.tcl"],
}

BIG_TESTS = [
    "repair_fanout6",
]

# TODO: Enable once difference between bazel and ctest is resolved.
MANUAL_FOR_BAZEL_TESTS = [
    "repair_tie11_hier",
    "repair_tie12_hier",
    "resize_slack2",
    "pin_swap1",
    "liberty_dont_use",
    "pinswap_flat",
    "pinswap_hier",
    "repair_fanout1_hier",
    "repair_fanout2_hier",
    "repair_fanout3_hier",
    "repair_setup4_flat",
    "repair_setup4_hier",
    "report_dont_use",
    "report_dont_use_corners",
    "split_load_hier",
]

[
    regression_test(
        name = test_name,
        size = "large" if test_name in BIG_TESTS else "medium",
        data = [":test_resources"] + extra_deps.get(test_name, []),
        tags = ["manual"] if test_name in MANUAL_FOR_BAZEL_TESTS else [],
    )
    for test_name in TESTS
]

cc_test(
    name = "rsz_buffer_removal",
    srcs = [
        "cpp/TestBufferRemoval.cc",
    ],
    data = [
        "Nangate45/Nangate45.lef",
        "Nangate45/Nangate45_typ.lib",
    ],
    deps = [
        "//src/ant",
        "//src/dbSta",
        "//src/dbSta:dbNetwork",
        "//src/dpl",
        "//src/est",
        "//src/grt",
        "//src/odb",
        "//src/rsz",
        "//src/sta:opensta_lib",
        "//src/stt",
        "//src/tst:nangate45_fixture",
        "//src/utl",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)

cc_test(
    name = "rsz_buffer_removal2",
    srcs = [
        "cpp/TestBufferRemoval2.cc",
    ],
    data = [
        "Nangate45/Nangate45.lef",
        "Nangate45/Nangate45_typ.lib",
    ],
    deps = [
        "//src/ant",
        "//src/dbSta",
        "//src/dbSta:dbNetwork",
        "//src/dpl",
        "//src/est",
        "//src/grt",
        "//src/odb",
        "//src/rsz",
        "//src/sta:opensta_lib",
        "//src/stt",
        "//src/tst:nangate45_fixture",
        "//src/utl",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)

cc_test(
    name = "rsz_buffer_removal3",
    srcs = ["cpp/TestBufferRemoval3.cc"],
    data = [
        "Nangate45/Nangate45.lef",
        "Nangate45/Nangate45_typ.lib",
        "cpp/TestBufferRemoval3_0.v",
        "cpp/TestBufferRemoval3_1.v",
        "cpp/TestBufferRemoval3_2.v",
        "cpp/TestBufferRemoval3_3.v",
        "cpp/TestBufferRemoval3_4.v",
        "cpp/TestBufferRemoval3_5.v",
        "cpp/TestBufferRemoval3_6.v",
        "cpp/TestBufferRemoval3_7.v",
        "cpp/TestBufferRemoval3_8.v",
        "cpp/TestBufferRemoval3_9.v",
    ],
    deps = [
        "//src/dbSta",
        "//src/dbSta:dbNetwork",
        "//src/odb",
        "//src/sta:opensta_lib",
        "//src/tst:integrated_fixture",
        "//src/utl",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)
